#define _CRT_SECURE_NO_WARNINGS 1
#include"string.h"
namespace itimate
{
	void string::reserve(size_t n)
	{
		if (n > _capacity)
		{
			char* tmp = new char[n + 1];
			strcpy(tmp, _str);
			delete[]_str;
			_str = tmp;
			_capacity = n;
		}
	}


	void string::push_back(char ch)
	{
		if (_size == _capacity)
		{
			reserve(_capacity == 0 ? 4 : _capacity * 2);
		}
		_str[_size] = ch;
		++_size;
		_str[_size] = '\0';
	}



	string& string::operator+= (char c)
	{
		push_back(c);
		return *this;
	}


	string& string::append(const char* s)
	{
		int len = strlen(s);
		if (_size + len > _capacity)
		{
			reserve(_size + len > _capacity * 2 ? _size + len : _capacity * 2);
		}
		for (int i = 0; i < len; i++)
		{
			_str[_size++] = s[i];
		}
		_str[_size] = '\0';
		return *this;
	}


	string& string::operator+= (const char* s)
	{
		append(s);
		return *this;
	}

	void string::resize(size_t n, char ch)
	{
		if (n > _capacity)
		{
			reserve(n);
			for (int i = 0; i < n - _size; i++)
			{
				_str[_size++] = 'ch';
			}
			_str[_size] = '\0';
		}
	}


	/*string& insert(size_t pos, const string& str)
	{

	}*/
}